<template>
	<div>
		<div class="container">
			<u--input placeholder="考试名称" border="surround" v-model="thing1"></u--input>
			<u--input placeholder="招聘人数" border="surround" v-model="thing2"></u--input>
			<u--input placeholder="报名时间" border="surround" v-model="time3"></u--input>
			<u--input placeholder="考试时间" border="surround" v-model="time4"></u--input>
			<u--input placeholder="备注" border="surround" v-model="thing5"></u--input>
			<u--input placeholder="跳转页面" border="surround" v-model="page"></u--input>
			<u-button type="primary" text="确定" @click="send(userOpenid[0])"></u-button>
		</div>
	</div>
</template>

<script>
import { mapActions } from 'vuex';
const db = wx.cloud.database();
import share from '../../common/share/index.vue';
export default {
	data() {
		return {
			thing1: "2024黑龙江省考公告",
			thing2: "8000",
			time3: "2024年1月20日",
			time4: "2024年3月9日",
			thing5: "2024年度黑龙江公务员考试公告已发布！",
			page: "pages/sk-tools/ggyy/index", 
			templateId: "vZSd8u06ZovsLBT9-4IFw47gegiReJDTelb8TISZ-Kk",
			userList: [],
			userOpenid: [],
			index: 0,
			
			MAX_LIMIT: 20,
			pages:0
		};
	},

	onShow() {},
	onPullDownRefresh() {
		console.log('refresh');
		setTimeout(function() {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	onLoad(options) {},
	computed: {},
	mounted() {
		this.getDyyh()
	},
	created() {},
	methods: {
		getDyyh(){
			let that = this
			db.collection('24sk_ggyy').where({
				templateId: that.templateId,
				status:1
			}).skip(that.pages * that.MAX_LIMIT).limit(that.MAX_LIMIT).get().then(res => {
				if(res.data.length > 0){
					that.userList = that.userList.concat(res.data)
					that.pages += 1
					that.getDyyh()
				}else{
					that.userOpenid = that.userList.map(item => item._openid)
				}
				
			})
			// wx.cloud.callFunction({
			// 	name: "get",
			// 	data: {
			// 		fncname: "24sk_ggyy"
			// 	},
			// 	success: function(res){
			// 		that.userOpenid = res.result.data.map(item => item._openid)
			// 	},
			// 	fail: function(req){
			// 		console.log(req)
			// 	}
			// })
		},
		send(openid) {
			let that = this;
			let data = {
				templateId: that.templateId,
				_openid: openid,
				page: that.page,
				subMsg: {
					thing1: {
						value: that.thing1
					},
					thing2: {
						value: that.thing2
					},
					time3: {
						value: that.time3
					},
					time4: {
						value: that.time4
					},
					thing5: {
						value: that.thing5
					}
				}
			}
			wx.cloud.callFunction({
				name: 'sendDyMsg',
				data: data,
				success:function(res){
					console.log(that.userOpenid[that.index] + " - 发送成功")
					
					if(that.index < that.userOpenid.length - 1){
						that.index += 1
						that.send(that.userOpenid[that.index])
					}
				},
				fail: function(req){
					console.log("发送失败",req)
					if(that.index < that.userOpenid.length - 1){
						that.index += 1
						that.send(that.userOpenid[that.index])
					}
				}
			})
				
			
		}
	},
	components: {}
};
</script>

<style lang="scss">
// @import url(./index.css);
</style>
